package stsj.meddroid.elements;

import stsj.meddroid.screen.BattleScreen;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;

public class GomuKing extends Enemy{
	private int state;
	private int count;
	private int counterAttack;
	public GomuKing(int x, int y){
		super(20,Enemy.GOMUKING,x,y, BattleScreen.texGomuKing);
		mySprite = new Sprite(BattleScreen.texGomuKing,0,0,80,80);
		mySprite.setPosition(x, y);
		mySprite.setRegion(0, 12, 60, 60);
		myRectangle = new Rectangle(x,y,mySprite.getWidth(),mySprite.getHeight());
		state = 0;
		count = 0;
		counterAttack = 0;
	}
	
	public void attack(){
		BattleScreen.medDroid.damaged(5);
		if (BattleScreen.medDroid.shieldOn){damaged(2);}
	}
	
	public void lasered(){
		super.lasered(10);
	}

	public void damaged(){
		super.damaged(2);
		BattleScreen.medDroid.damaged(5);
	}

	public void dropOrb(){
		super.dropOrb(38);
	}
	
	public void moveRight(){
		super.moveRight();
		state++;
		mySprite.setScale(1, 1);
		mySprite.setRegion((state%2)*64, 12, 60, 60);
	}
	
	public void moveLeft(){
		if (state < 60){
		super.moveLeft();
		}else{
			double i = Math.random();
			if (i <= 0.5){super.moveRight();}
			else {super.moveLeft();}
		}
		state++;
		mySprite.setRegion((state%2)*64, 12, 60, 60);
		mySprite.setScale(-1, 1);
		if(state == 90) {state = 0;}
	}
	
	public void autoMove(){
		if (count != 8) {count++;}
		else{
			if (state < 30){				
				face = RIGHT;
				moveRight();
			}
			else{
				face = LEFT;
				moveLeft();
			}
			if (!BattleScreen.medDroid.invisibleOn){
				if (counterAttack != 8) {counterAttack++;}
				else {
					if (Math.abs(BattleScreen.centerX - (x+mySprite.getWidth()/2)) <= 75 && Math.abs(BattleScreen.centerY - (y+mySprite.getHeight()/2)) <= 80) {
						attack();
					}
					counterAttack = 0;
				}
			}
			count = 0;
		}
	}
}
